This tutorial is set to accompany the paper by Zaidi & White, et al. “Facial masculinity does not appear to be a condition-dependent male ornament in humans and does not reflect MHC heterozygosity” to provide the user with a way of visualizing dense heatmaps on facial scans.

The Plot1Face.R function in written by Tomas Gonzalez-Zarzar. Follow him at: https://github.com/tomszar

Load necessary libraries

require(plotly)
## Loading required package: plotly
## Warning: package 'plotly' was built under R version 3.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
require(mixOmics)
## Loading required package: mixOmics
## Warning: package 'mixOmics' was built under R version 3.3.2
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:plotly':
## 
##     select
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.3.2
## 
## Loaded mixOmics 6.3.1
## 
## Visit http://www.mixOmics.org for more details about our methods.
## Any bug reports or comments? Notify us at mixomics at math.univ-toulouse.fr or https://bitbucket.org/klecao/package-mixomics/issues
## 
## Thank you for using mixOmics!
require(data.table)
## Loading required package: data.table
## Warning: package 'data.table' was built under R version 3.3.2

Read in provided obj file. The contains information for the template face on top of which heatmaps can be visualized. The file contains 7,150 landmark vertices and accompanying triangle facet information.

RefScan <- read.table("../Dataset/RefScan.obj", sep = "\t", header = F)
head(RefScan)
##   V1       V2        V3         V4
## 1  v 1.141250 0.2749210 -0.6589722
## 2  v 1.141896 0.2429964 -0.6642452
## 3  v 1.140617 0.2109406 -0.6674274
## 4  v 1.138494 0.1772384 -0.6708966
## 5  v 1.135103 0.2716909 -0.6310956
## 6  v 1.133698 0.3032659 -0.6246518

Split the information into vertices and facets matrices.

RefScan_Vertices <- as.matrix(RefScan[which(RefScan$V1 == "v"), 2:4])
RefScan_Facets <- as.matrix(RefScan[which(RefScan$V1 == "f"), 2:4])
head(RefScan_Vertices)
##         V2        V3         V4
## 1 1.141250 0.2749210 -0.6589722
## 2 1.141896 0.2429964 -0.6642452
## 3 1.140617 0.2109406 -0.6674274
## 4 1.138494 0.1772384 -0.6708966
## 5 1.135103 0.2716909 -0.6310956
## 6 1.133698 0.3032659 -0.6246518
head(RefScan_Facets)
##      V2 V3 V4
## 7151 98 79 95
## 7152 79 83 65
## 7153 79 98 83
## 7154 58 65 83
## 7155 58 60 44
## 7156 58 70 60

Initialize Plot1Face function from source file

source('../Scripts/Plot1Face.R')

Example of plotting a face in greyscale, with no heatmap information.

Plot1Face(vertices = RefScan_Vertices, facets = RefScan_Facets, colormap = NULL, title = "Example greyscale face")

Examples using results from Zaidi and White, et al. paper.

Read in FM_QL file

qlmasc<-fread("../Dataset/qlmasc_1233_noprop_03292018.txt",header=F)

Plot facial masculinity of a face which has greater overall facial masculinity than the female consensus face

#read dataframe containing IDs and overall facial masculinity measurements
eurofam<-read.table("../Dataset/euro_1233_masc_het_03292018.dat",sep="\t",header=T)
#determine the index in the ql file which corresponds to the ID you are looking for
id1.index<-sample(which(eurofam$avg.masc.unit>2),1)
#isolate the FM_ql values for this person
id1.ql<-t(qlmasc[id1.index,])
Plot1Face(vertices = RefScan_Vertices, facets = RefScan_Facets, colormap = id1.ql, title = "FM_ql")

Plot geometric sexual dimorphism for each vertex and Cohen’s D estimate for each vertex (or any other statistic e.g. effect size of predictor/p-value etc.)

#Geometric sexual dimorphism
ql_gsd <- read.table("../Results/Summary_dat/ql_gsd_03292018.txt", sep = "\t", header = T)
head(ql_gsd)
##            x
## 1 0.02719198
## 2 0.02770744
## 3 0.02792874
## 4 0.02777141
## 5 0.02781449
## 6 0.02702272
#Cohen's D
ql_sex_cohenD <- read.table("../Results/Summary_dat/ql_sex_cohenD_03292018.txt", sep = "\t", header = T)
head(ql_sex_cohenD)
##          x
## 1 1.103417
## 2 1.109931
## 3 1.103388
## 4 1.087611
## 5 1.127053
## 6 1.108396

Add colors to the face representing the sexual dimorphism at each vertex.

Plot1Face(vertices = RefScan_Vertices, facets = RefScan_Facets, colormap = ql_gsd$x, title = "Geometric sexual dimorphism")

Add colors to the face representing the Cohen’s D estimate for sex difference at each vertex.

Plot1Face(vertices = RefScan_Vertices, facets = RefScan_Facets, colormap = ql_sex_cohenD$x, title = "Cohen's D estimate for sexual dimorphism")

The color scale can be adjusted to a specified minimum and maximum Otherwise it defaults to the minimum and maximum of the values provided

Plot1Face(vertices = RefScan_Vertices, facets = RefScan_Facets, colormap = ql_sex_cohenD$x, title = "Cohen's D estimate for sexual dimorphism",color.min = 0,color.max=3)